import java.util.ArrayList;
import java.util.List;

public class MyCollection <T> {

	private List <T> collection;
	private Observer <T> feedbackObserver;
	
	public MyCollection () {
		collection = new ArrayList <T> ();
		
		// clasa anonima, instantiata si implementata pe loc
		feedbackObserver = new Observer <T> () {

			@Override
			public void observeAdd(T arg) {
				System.out.println("Successfully added object " + arg);
			}

			@Override
			public void observeRemove(T arg) {
				System.out.println("Successfully removed object " + arg);
			}
		};
	}
	
	public boolean add (T arg) {
		boolean result = collection.add(arg);
		if (result)
			feedbackObserver.observeAdd(arg);
		
		return result;
	}
	
	public boolean remove (T arg) {
		boolean result = collection.remove(arg);
		if (result)
			feedbackObserver.observeRemove(arg);
		
		return result;
	}
}
